package com.example.shop.service.impl;

import com.example.shop.entity.Article;
import com.example.shop.dao.ArticleMapper;
import com.example.shop.service.ArticleService;
import org.springframework.stereotype.Service;
import jakarta.annotation.Resource;

/**
 * (Article)表服务实现类
 *
 * @author makejava
 * @since 2025-03-26 09:24:38
 */
@Service("articleService")
public class ArticleServiceImpl implements ArticleService {
    @Resource
    private ArticleMapper articleMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param articleid 主键
     * @return 实例对象
     */
    @Override
    public Article queryById(Integer articleid) {
        return this.articleMapper.queryById(articleid);
    }


    /**
     * 新增数据
     *
     * @param article 实例对象
     * @return 实例对象
     */
    @Override
    public Article insert(Article article) {
        this.articleMapper.insert(article);
        return article;
    }

    /**
     * 修改数据
     *
     * @param article 实例对象
     * @return 实例对象
     */
    @Override
    public Article update(Article article) {
        this.articleMapper.update(article);
        return this.queryById(article.getArticleid());
    }

    /**
     * 通过主键删除数据
     *
     * @param articleid 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer articleid) {
        return this.articleMapper.deleteById(articleid) > 0;
    }
}
